package com.um2.simplexe.client.plugins.ui.c2D;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;

import vue.panneau1.Zone1;
import vue.panneau2.Zone2;
import vue.panneau2.controle.NouveauResultatPointListener;
import vue.panneau3.Zone3;
import vue.util.Point;
import vue.util.Util;


import com.um2.simplexe.client.ui.exec.ToutesLesMethodesClient;
import com.um2.simplexe.client.ui.util.controleUI.chargeur.menu.ControleurDeMenu;

import controle.ControleActionMenu;




public class UIClient2D implements ControleurDeMenu, NouveauResultatPointListener {

	
	ToutesLesMethodesClient methodes = null ;
	private Zone2 z2;
	private Zone3 z3;
	private Zone1 z1;
	
	
	public Vector<JMenu> ajouterALaMenuBar() {


		Vector<JMenu> res = new Vector<JMenu>() ;
				
				// menu Fichier
				JMenu menu = new JMenu("Fichier");
				menu.setMnemonic('F');
				
				res.add(menu) ;
				
				
				JMenu menu2 = new JMenu("Nouveau");
				menu2.setMnemonic('N');
				menu2.setIcon(Util.createImageIcon("img/new.png"));

//				res.add(menu2) ;
				
				JMenuItem it2D = new JMenuItem("2D");
				it2D.setMnemonic('2');
				it2D.setActionCommand("nouveau2D");
				it2D.setAccelerator(KeyStroke.getKeyStroke("ctrl F2"));
//				it2D.addActionListener(new ControleActionMenu(this));		
				menu2.add(it2D);

				// demande de nouveau panneaux 2D:
				it2D.addActionListener(new ActionListener() {

					public void actionPerformed(ActionEvent e) {
						nouveauPanneaux2D() ;
					}

					}) ;
				
				
				
				JMenuItem it3D = new JMenuItem("3D");
				it3D.setMnemonic('3');
				it3D.setActionCommand("nouveau3D");
				it3D.setAccelerator(KeyStroke.getKeyStroke("ctrl F3"));
//				it3D.addActionListener(new ControleActionMenu(this,listeOnglets));		
				menu2.add(it3D);
				
				menu.add(menu2);
				
				JMenuItem itOuvrir = new JMenuItem("Ouvrir...");
				itOuvrir.setMnemonic('O');
				itOuvrir.setActionCommand("ouvrir");
				itOuvrir.setIcon(Util.createImageIcon("img/open.png"));
				itOuvrir.setAccelerator(KeyStroke.getKeyStroke("ctrl O"));
//				itOuvrir.addActionListener(new ControleActionMenu(this,listeOnglets));
				menu.add(itOuvrir);
//				menu.addSeparator();
				
				JMenuItem itFermer = new JMenuItem("Fermer");
				itFermer.setMnemonic('F');
				itFermer.setActionCommand("fermer");
				itFermer.setIcon(Util.createImageIcon("img/no.png"));
				itFermer.setAccelerator(KeyStroke.getKeyStroke("ctrl W"));
//				itFermer.addActionListener(new ControleActionMenu(this,listeOnglets));
				menu.add(itFermer);
				
				JMenuItem itFermertout = new JMenuItem("Fermer tout");
				itFermertout.setMnemonic('T');
				itFermertout.setActionCommand("fermer_tout");
				itFermertout.setIcon(Util.createImageIcon("img/no.png"));
				itFermertout.setAccelerator(KeyStroke.getKeyStroke("ctrl shift W"));
//				itFermertout.addActionListener(new ControleActionMenu(this,listeOnglets));
				menu.add(itFermertout);
//				menu.addSeparator();
				
				JMenuItem itEnregistrer = new JMenuItem("Enregistrer");
				itEnregistrer.setMnemonic('g');
				itEnregistrer.setActionCommand("enregistrer");
				itEnregistrer.setIcon(Util.createImageIcon("img/save.png"));
				itEnregistrer.setAccelerator(KeyStroke.getKeyStroke("ctrl S"));
//				itEnregistrer.addActionListener(new ControleActionMenu(this,listeOnglets));
				menu.add(itEnregistrer);
				
				JMenuItem itEnregistrersous = new JMenuItem("Enregistrer sous");
				itEnregistrersous.setMnemonic('r');
				itEnregistrersous.setActionCommand("enregistrer_sous");
				itEnregistrersous.setIcon(Util.createImageIcon("img/save_as.png"));
//				itEnregistrersous.addActionListener(new ControleActionMenu(this,listeOnglets));
				menu.add(itEnregistrersous);
//				menu.addSeparator();
				
				JMenuItem itImprimer = new JMenuItem("Imprimer...");
				itImprimer.setMnemonic('I');
				itImprimer.setActionCommand("imprimer");
				itImprimer.setIcon(Util.createImageIcon("img/print.png"));
				itImprimer.setAccelerator(KeyStroke.getKeyStroke("ctrl P"));
//				itImprimer.addActionListener(new ControleActionMenu(this,listeOnglets));	
				menu.add(itImprimer);	
//				menu.addSeparator();
				
				JMenuItem itExportPdf = new JMenuItem("Exporter en PDF");
				itExportPdf.setMnemonic('E');
				itExportPdf.setActionCommand("export_pdf");
				itExportPdf.setIcon(Util.createImageIcon("img/pdf.gif"));
//				itExportPdf.addActionListener(new ControleActionMenu(this,listeOnglets));	
				menu.add(itExportPdf);
//				menu.addSeparator();
				
				JMenuItem itQuitter = new JMenuItem("Quitter");
				itQuitter.setMnemonic('Q');
				itQuitter.setActionCommand("quitter");
				itQuitter.setIcon(Util.createImageIcon("img/exit.png"));
				itQuitter.setAccelerator(KeyStroke.getKeyStroke("alt F4"));
//				itQuitter.addActionListener(new ControleActionMenu(this,listeOnglets));	
				menu.add(itQuitter);	
				
//				this.add(menu);
				
				// menu ?
				JMenu menuEEE = new JMenu("?");
				menuEEE.setMnemonic('?');
				
				
				res.add(menuEEE) ;
				
				
				JMenuItem itAide = new JMenuItem("Aide sur Simplexe");
				itAide.setMnemonic('A');
				itAide.setActionCommand("aide");
				itAide.setIcon(Util.createImageIcon("img/help.png"));
				itAide.setAccelerator(KeyStroke.getKeyStroke("F1"));
//				itAide.addActionListener(new ControleActionMenu(this,listeOnglets));
				
				menuEEE.add(itAide);
				
				JMenuItem itApropos = new JMenuItem("       A propos de...");
				itApropos.setMnemonic('p');
				itApropos.setActionCommand("aproposde");
//				itApropos.addActionListener(new ControleActionMenu(this,listeOnglets));
				
				menuEEE.add(itApropos);		
//				this.add(menu);	
				
//				this.agirItemsOnglet();
		
		
		return res;
	}

	public JPanel getInfosPlugin() {
		return new JPanel();
	}

	public String getNomPlugin() {
		return "plugin interface 2D";
	}

	public void setListeFonctionsDisponibles(ToutesLesMethodesClient methodes) {
		this.methodes = methodes ;
	}

	
	
	
	private void nouveauPanneaux2D() {
		z2 = new Zone2();
		z3 = new Zone3(false);
		z1 = new Zone1(z2,z3,false);
		
		
		
		z2.addNouveauResultatPointListener(this);
	
		
		this.methodes.ajouterALaZone1("2D", z1.getInterface2DZone1());
		this.methodes.ajouterALaZone3("2D",(JPanel) z2.getContentPane());
		this.methodes.ajouterALaZone2("2D", z3.getModele().getJpanel());	
	}

	public void changerResultatPoint(float x1, float x2, int numeroMatrice, String libelle) {
		z2.getContentPane().repaint() ;
		z3.getModele().setPoint2DUnique(new Point(x1,x2,numeroMatrice,libelle)) ;
	}

	
	
}









